﻿$(function () {
    //时间预约 Order
    var TimeNum1YStart,
    i = 0,
    CityYPos = 0;
    var CityListTouchableHeight = 0;//可拖动区域高度
    //单个元素高度
    var touchHeight = 27
    var EndI;
    document.addEventListener("touchstart", touchStart, false);
    document.addEventListener("touchmove", touchMove, false);
    document.addEventListener("touchend", touchEnd, false);

    function touchStart(e) {
        TimeNum1YStart = e.touches[0].clientY;
        CityListTouchableHeight = touchHeight * ($('.CityListItem li').length - 2);
    }
    function touchMove(e) {
        e.preventDefault();
        var maxScrollHeight = parseInt(e.changedTouches[0].clientY - TimeNum1YStart) + parseInt(CityYPos);
        $('.CityListItem').css('top', maxScrollHeight + 'px');
        i = Math.abs((parseInt($('.CityListItem').css('top')) - 10) / touchHeight).toFixed(0);
        $('.CityListItem li').removeClass('CitySelectListFocus');
        $('.CityListItem li').eq(i).addClass('CitySelectListFocus');
    }

    function touchEnd(e) {
        EndI = -(parseInt($('.CityListItem').css('top')) - 13) / touchHeight;
        EndI = EndI.toFixed(0)
        var maxScrollHeight = touchHeight * (EndI - 1);
        $('.CityListItem').css('top', -maxScrollHeight + 'px');
        $('.CityListItem li').removeClass('CitySelectListFocus');
        $('.CityListItem li').eq(EndI).addClass('CitySelectListFocus');

        if (parseInt($('.CityListItem').css('top')) >= 0) {
            $('.CityListItem').css('top', '0px');
            $('.CityListItem li').removeClass('CitySelectListFocus');
            $('.CityListItem li').eq(1).addClass('CitySelectListFocus');
        }
        if (parseInt($('.CityListItem').css('top')) <= -CityListTouchableHeight) {
            $('.CityListItem').css('top', -CityListTouchableHeight);
            $('.CityListItem li').removeClass('CitySelectListFocus');
            $('.CityListItem li').eq($('.CityListItem li').length - 1).addClass('CitySelectListFocus');
        }
        CityYPos = $('.CityListItem').css('top');
    }
    $('.OrderTimeFir').children('.OrderTimeFirFocus')
}
);
